/**
 * 
 */
package prepro;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

/**
 * @author J.Feit 07.12.2010 14:15:45
 */
public class Convert {

	/**
	 * @param args
	 */
	public static FileOutputStream bw;
	public static OutputStreamWriter out;

	public static void main(String[] args) throws FileNotFoundException,
			IOException {
		// TODO Auto-generated method stub
		String path = "/local/joofeit/Dewac";
		// String path = "/home/joo/Desktop/test";
		bw = new FileOutputStream(new File("/local/joofeit/out/out"));
		// bw = new FileOutputStream(new File("/home/joo/Desktop/outXX"));
		out = new OutputStreamWriter(bw, "UTF-8");
		searchFolders(path, out);
	}

	public static void searchFolders(String path, OutputStreamWriter out)
			throws FileNotFoundException, IOException {
		// System.out.println("JJaaaaaaaaaaa");

		File file = new File(path);
		if (file.isDirectory()) {
			String[] fileList = file.list();
			for (String s : fileList) {
				System.out.println("File :" + path + "/" + s);
				if (s.endsWith("txt")) {
					InputStreamReader ireader = new InputStreamReader(
							new FileInputStream(new File(path + "/" + s)),
							"windows-1252");

					BufferedReader breader = new BufferedReader(ireader);
					String line = "";
					while ((line = breader.readLine()) != null) {
						// System.out.println("Line: " + line);
						String newl = line.replaceAll("\\s+", " ");
						// System.out.println(newl);
						String[] lineSplit = newl.split(" ");
						if (lineSplit.length > 2) {
							// System.out.println("Length " + lineSplit.length);
							out.append(lineSplit[0] + " " + lineSplit[1] + " "
									+ lineSplit[2] + "\n");

						}
						if (lineSplit.length == 1) {
							out.append("\n");
						}

					}
				}

			}

		}
	}
}